import pygame


class Music():
    def __init__(self):
        # 混音器初始化
        pygame.mixer.init()
        pygame.mixer.music.load("./music/bg.mp3")

    def start_music(self):
        """开启背景音乐，并无限循环"""
        pygame.mixer.music.play(-1)

    def close_music(self):
        """关闭音乐"""
        pygame.mixer.music.stop()

    def hit_music(self,stats):
        """射击的音效"""
        if stats.game_active:
            hit = pygame.mixer.Sound("./music/hit.wav")
            hit.play()

    def blast_music(self):
        """爆炸的音效"""
        blast = pygame.mixer.Sound("./music/blast.wav")
        blast.play()

    def level_music(self):
        """升级的音效"""
        level = pygame.mixer.Sound("./music/level.wav")
        level.play()